import pandas as pd
import datetime
from anneal_solver import solvelog_dwave
from dwave_qbsolv import QBSolv
from tabu import TabuSampler
import plotly.express as px
import neal
from schedule import *
from dwave.system import DWaveSampler, EmbeddingComposite
import plotly.io as pio
import pickle
from os import listdir
from os.path import isfile, join
pio.renderers.default = "notebook"
import lab_runner
try_all=False
There is some bug in which the previos run influences the qubo of the next run and i have not found the cause yet
s1 = Schedule(time_max=5)
s1.build_machines(1)
s1.create_job({0: (1, 1)})
q1=lab_runner.run_scaling_experiment(s1,True);
q1.plot_connections_qubo_states()
qbits: 5
[[0], [state(j:0,m:0,t:0)], -1.0, {1: -1, 2: 0, 3: 0, 4: 0, 5: 0.0}, 1]
l_df1=lab_runner.load_experiments(s1)
df1 = pd.concat(l_df1, ignore_index=True)
px.histogram(df1, "energy")
s2 = Schedule(time_max=5)
s2.build_machines(2)
s2.create_job({0: (1, 1), 1: (1, 1)})
q2=lab_runner.run_scaling_experiment(s2,True)
q2.plot_connections_qubo_states()
qbits: 10
[[3, 9], [state(j:0,m:0,t:3), state(j:0,m:1,t:4)], -2.0, {1: -2, 2: 0, 3: 0, 4: 0, 5: 0.0}, 2]
l_df2=lab_runner.load_experiments(s2)
df2 = pd.concat(l_df2, ignore_index=True)
px.histogram(df2,"energy")
s3 = Schedule(time_max=5)
s3.build_machines(2)
s3.create_job({0: (1, 1), 1: (1, 1)})
s3.create_job({0: (1, 1), 1: (1, 1)})
q3=lab_runner.run_scaling_experiment(s3,True)
q3.plot_connections_qubo_states()
qbits: 20
[[1, 8, 14, 17], [state(j:0,m:0,t:1), state(j:0,m:1,t:3), state(j:1,m:0,t:4), state(j:1,m:1,t:2)], -4.0, {1: -4, 2: 0, 3: 0, 4: 0, 5: 0.0}, 4]
l_df3=lab_runner.load_experiments(s3)
df3 = pd.concat(l_df3, ignore_index=True)
px.histogram(df3,"energy")
s4 = Schedule(time_max=5)
s4.build_machines(3)
s4.create_job({0: (1, 1), 1: (1, 1), 2: (1, 1)})
s4.create_job({0: (1, 1), 1: (1, 1), 2: (1, 1)})
q4=lab_runner.run_scaling_experiment(s4,True)
q4.plot_connections_qubo_states()
qbits: 30
[[4, 6, 16, 13, 24, 25], [state(j:0,m:0,t:4), state(j:0,m:1,t:1), state(j:1,m:0,t:1), state(j:0,m:2,t:3), state(j:1,m:1,t:4), state(j:1,m:2,t:0)], -6.0, {1: -6, 2: 0, 3: 0, 4: 0, 5: 0.0}, 6]
l_df4 = lab_runner.load_experiments(s4)
df4 = pd.concat(l_df4, ignore_index=True)
px.histogram(df4, "energy")
s5 = Schedule(time_max=5)
s5.build_machines(3)
s5.create_job({0: (1, 1), 1: (1, 1), 2: (1, 1)})
s5.create_job({0: (1, 1), 1: (1, 1), 2: (1, 1)})
s5.create_job({0: (1, 1), 1: (1, 1), 2: (1, 1)})
q5=lab_runner.run_scaling_experiment(s5,True)
q5.plot_connections_qubo_states()
qbits: 45
[[0, 11, 16, 9, 34, 36, 23, 25, 42], [state(j:0,m:0,t:0), state(j:0,m:2,t:1), state(j:1,m:0,t:1), state(j:0,m:1,t:4), state(j:2,m:0,t:4), state(j:2,m:1,t:1), state(j:1,m:1,t:3), state(j:1,m:2,t:0), state(j:2,m:2,t:2)], -9.0, {1: -9, 2: 0, 3: 0, 4: 0, 5: 0.0}, 9]
l_df5 = lab_runner.load_experiments(s5)
df5 = pd.concat(l_df5, ignore_index=True)
px.histogram(df5, "energy")
s6 = Schedule(time_max=5)
s6.build_machines(3)
s6.create_job({0: (1, 1), 1: (1, 1), 2: (1, 1)})
s6.create_job({0: (1, 1), 1: (1, 1), 2: (1, 1)})
s6.create_job({0: (1, 1), 1: (1, 1), 2: (1, 1)})
s6.create_job({0: (1, 1), 1: (1, 1), 2: (1, 1)})
q6=lab_runner.run_scaling_experiment(s6,True)
q6.plot_connections_qubo_states()
qbits: 60
[[0, 6, 32, 18, 14, 49, 50, 24, 40, 27, 58], [state(j:0,m:0,t:0), state(j:0,m:1,t:1), state(j:2,m:0,t:2), state(j:1,m:0,t:3), state(j:0,m:2,t:4), state(j:3,m:0,t:4), state(j:3,m:1,t:0), state(j:1,m:1,t:4), state(j:2,m:2,t:0), state(j:1,m:2,t:2), state(j:3,m:2,t:3)], -11.0, {1: -11, 2: 0, 3: 0, 4: 0, 5: 0.0}, 12]
l_df6 = lab_runner.load_experiments(s6)
df6 = pd.concat(l_df6, ignore_index=True)
px.histogram(df6, "energy")
s7 = Schedule(time_max=7)
s7.build_machines(3)
s7.create_job({0: (1, 1), 1: (1, 1), 2: (1, 1)})
s7.create_job({0: (1, 1), 1: (1, 1), 2: (1, 1)})
s7.create_job({0: (1, 1), 1: (1, 1), 2: (1, 1)})
s7.create_job({0: (1, 1), 1: (1, 1), 2: (1, 1)})
q7=lab_runner.run_scaling_experiment(s7,True)
qbits: 84
[[6, 14, 43, 9, 24, 68, 71, 54, 34, 60, 83], [state(j:0,m:0,t:6), state(j:0,m:2,t:0), state(j:2,m:0,t:1), state(j:0,m:1,t:2), state(j:1,m:0,t:3), state(j:3,m:0,t:5), state(j:3,m:1,t:1), state(j:2,m:1,t:5), state(j:1,m:1,t:6), state(j:2,m:2,t:4), state(j:3,m:2,t:6)], -11.0, {1: -11, 2: 0, 3: 0, 4: 0, 5: 0.0}, 12]
l_df7 = lab_runner.load_experiments(s7)
df7 = pd.concat(l_df7, ignore_index=True)
px.histogram(df7, "energy")
#no embedding
if try_all:
s8 = Schedule(time_max=7)
s8.build_machines(4)
s8.create_job({0: (1, 1), 1: (1, 1), 2: (1, 1), 3: (1, 1)})
s8.create_job({0: (1, 1), 1: (1, 1), 2: (1, 1), 3: (1, 1)})
s8.create_job({0: (1, 1), 1: (1, 1), 2: (1, 1), 3: (1, 1)})
s8.create_job({0: (1, 1), 1: (1, 1), 2: (1, 1), 3: (1, 1)})
q8=lab_runner.run_scaling_experiment(s8)
q8.plot_connections_qubo_states()
#no embedding
if try_all:
s9 = Schedule(time_max=10)
s9.build_machines(4)
s9.create_job({0: (1, 1), 1: (1, 1), 2: (1, 1), 3: (1, 1)})
s9.create_job({0: (1, 1), 1: (1, 1), 2: (1, 1), 3: (1, 1)})
s9.create_job({0: (1, 1), 1: (1, 1), 2: (1, 1), 3: (1, 1)})
s9.create_job({0: (1, 1), 1: (1, 1), 2: (1, 1), 3: (1, 1)})
q9=lab_runner.run_scaling_experiment(s9)
s10 = Schedule(time_max=5)
s10.build_machines(3)
s10.create_job({0: (1, 1), 1: (1, 1), 2: (1, 1)})
s10.create_job({0: (1, 1), 1: (1, 1), 2: (1, 1)})
s10.create_job({0: (1, 1), 1: (1, 1), 2: (1, 1)})
s10.create_job({0: (1, 1), 1: (1, 1), 2: (1, 1)})
s10.create_job({0: (1, 1), 1: (1, 1), 2: (1, 1)})
q10=lab_runner.run_scaling_experiment(s10,True)
q10.plot_connections_qubo_states()
qbits: 75
[[30, 11, 16, 7, 48, 64, 20, 54, 55, 72, 28, 44], [state(j:2,m:0,t:0), state(j:0,m:2,t:1), state(j:1,m:0,t:1), state(j:0,m:1,t:2), state(j:3,m:0,t:3), state(j:4,m:0,t:4), state(j:1,m:1,t:0), state(j:3,m:1,t:4), state(j:3,m:2,t:0), state(j:4,m:2,t:2), state(j:1,m:2,t:3), state(j:2,m:2,t:4)], -12.0, {1: -12, 2: 0, 3: 0, 4: 0, 5: 0.0}, 15]
l_df10 = lab_runner.load_experiments(s10)
df10 = pd.concat(l_df10, ignore_index=True)
px.histogram(df10, "energy")
s11 = Schedule(time_max=5)
s11.build_machines(4)
s11.create_job({ 1: (1, 1), 2: (1, 1), 3: (1, 1)})
s11.create_job({0: (1, 1), 2: (1, 1), 3: (1, 1)})
s11.create_job({0: (1, 1), 1: (1, 1), 2: (1, 1)})
s11.create_job({0: (1, 1), 2: (1, 1), 3: (1, 1)})
q11=lab_runner.run_scaling_experiment(s11,True)
q11.plot_connections_qubo_states()
qbits: 84
[[6, 18, 49, 15, 52, 33, 76, 37, 80, 43, 67], [state(j:0,m:1,t:0), state(j:0,m:3,t:2), state(j:2,m:1,t:2), state(j:0,m:2,t:4), state(j:2,m:2,t:0), state(j:1,m:2,t:1), state(j:3,m:2,t:2), state(j:1,m:3,t:0), state(j:3,m:3,t:1), state(j:2,m:0,t:1), state(j:3,m:0,t:4)], -11.0, {1: -11, 2: 0, 3: 0, 4: 0, 5: 0.0}, 12]
l_df11 = lab_runner.load_experiments(s11)
df11 = pd.concat(l_df11, ignore_index=True)
px.histogram(df11, "energy")
s12 = Schedule(time_max=5)
s12.build_machines(4)
s12.create_job({0: (1, 1), 1: (1, 1), 2: (1, 1), 3: (1, 1)})
s12.create_job({0: (1, 1), 1: (1, 1), 2: (1, 1), 3: (1, 1)})
s12.create_job({0: (1, 1), 1: (1, 1), 2: (1, 1), 3: (1, 1)})
s12.create_job({0: (1, 1), 1: (1, 1), 2: (1, 1), 3: (1, 1)})
q12=lab_runner.run_scaling_experiment(s12,True)
q12.plot_connections_qubo_states()
qbits: 80
[[5, 20, 16, 61, 12, 43, 26, 67, 54, 75, 57, 39], [state(j:0,m:1,t:0), state(j:1,m:0,t:0), state(j:0,m:3,t:1), state(j:3,m:0,t:1), state(j:0,m:2,t:2), state(j:2,m:0,t:3), state(j:1,m:1,t:1), state(j:3,m:1,t:2), state(j:2,m:2,t:4), state(j:3,m:3,t:0), state(j:2,m:3,t:2), state(j:1,m:3,t:4)], -12.0, {1: -12, 2: 0, 3: 0, 4: 0, 5: 0.0}, 16]
l_df12 = lab_runner.load_experiments(s12)
df12 = pd.concat(l_df12, ignore_index=True)
px.histogram(df12, "energy")
response = QBSolv().sample_qubo(q12.J, num_repeats=100)
sol3 = response.samples()[0]
*temp, _ = q12.interpret_solution_dict(sol3)
print(temp)
q12.plot_solution()
[[2, 8, 10, 16, 20, 26, 33, 39, 44, 45, 52, 58, 63, 69, 71, 77], [state(j:0,m:0,t:2), state(j:0,m:1,t:3), state(j:0,m:2,t:0), state(j:0,m:3,t:1), state(j:1,m:0,t:0), state(j:1,m:1,t:1), state(j:1,m:2,t:3), state(j:1,m:3,t:4), state(j:2,m:0,t:4), state(j:2,m:1,t:0), state(j:2,m:2,t:2), state(j:2,m:3,t:3), state(j:3,m:0,t:3), state(j:3,m:1,t:4), state(j:3,m:2,t:1), state(j:3,m:3,t:2)], -16.0, {1: -16, 2: 0, 3: 0, 4: 0, 5: 0.0}, 16]